package wang.naifei.core.utils.os.linux;/*
 * <h3>Title:SynologyService系统</h3>
 * <p>Copyright (c) 2022, wnfbx. All rights reserved.</p>
 * @author wnfbx
 */

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;

/**
 * <dt>Description:UnsafeLinuxShellHelper</dt>
 * <dd>不安全的shell脚本帮助类</dd>
 *
 * @author wnfbx
 * @version 1.0 <i>2022/1/2 17:40</i>
 * @since jdk1.7+
 */
public class LinuxShellHelper {

    private static final Logger log = LoggerFactory.getLogger(LinuxShellHelper.class);

    private static List<String> unsafeCommands = null;

    static {
        Properties properties = new Properties();
        try {
            properties.load(LinuxShellHelper.class.getResourceAsStream("LinuxShellCommands.properties"));
            String unsafeCommandsProp = properties.getProperty("unsafeCommands");
            log.debug("read unsafeCommands:{}", unsafeCommandsProp);
            unsafeCommands = Arrays.asList(unsafeCommandsProp.split(","));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static boolean isUnSafe(String shell) {
        return unsafeCommands.contains(shell.trim().split(" ")[0]);
    }
}
